import sys
from PyQt5.QtWidgets import QApplication  ,QWidget ,QHBoxLayout , QPushButton
import random
import sys
import cv2
import os
import numpy as np
import json
import threading
import time

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import QPalette, QBrush, QPixmap
from PyQt5.QtCore import QTimer
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from get_config import *
import ClientUi.plc.ModbusAssistant as ModbusAssistant
from logAgent.logManager import Loger


class AlgSetDlg(QWidget):

    def __init__(self,parent=None):
        super(AlgSetDlg,self).__init__(parent)
        currentPath = os.path.abspath(__file__)
        path = os.path.dirname(currentPath)
        clientUiPath = os.path.dirname(path)
        self.setWindowIcon(QIcon(f'{clientUiPath}\\images\\icon.ico'))  # 设置窗口图标
        self.setWindowTitle('流程设置')

        # 获取屏幕尺寸
        screen = QDesktopWidget().screenGeometry()
        mar = QMargins(int(screen.width()*0.15), int(screen.height()*0.15), int(screen.width()*0.15), int(screen.height()*0.15))
        newRct = screen.marginsRemoved(mar)
        self.setGeometry(newRct)

        mystr = 'qiepian yolorect erzhihua danzhang haikang daheng dushen maide dalsa usbcamera moni okimgsave ngimgsave ngimgret imgbmpsave donotmodel isskip'
        tnames = mystr.split()
        for name in tnames:
            #print("set name:", name)
            t = config[name] if name in config.keys() else False
            config[name] = t

        myli = 'Camera1 Camera2 Camera3 Camera4 Camera5 Camera6 Camera7 Camera8 '.split()
        for name in myli:
            t = config[name] if name in config.keys() else [0,0]
            config[name] = t
        config_save()

        vlayout = QVBoxLayout()
        tab = QTabWidget()
        vlayout.addWidget(tab)
        tab.addTab(self.__createPretreatmentePage(), '预处理')
        tab.addTab(self.__createParamsSetPage(), '参数设置')
        tab.addTab(self.__createPosttreatmentPage(), '后处理')
        tab.addTab(self.__createImageSavePage(), '图像保存')
        tab.addTab(self.__createCameraSizeAndAlg(), '图像尺寸及算法设置')
        tab.addTab(self.__createDebugPage(), '调试')
        tab.addTab(self.__createUiSetPage(), '界面设置')

        self.setLayout(vlayout)

        #self.denglu.clicked.connect(self.fun_11)
        #self.biaohaoshezhi.clicked.connect(self.fun_13)
        self.mybt1.clicked.connect(self.fun_1)
        self.mybtck.clicked.connect(self.fun_ck)
        self.bt1.clicked.connect(self.fun1)
        self.qiepian.stateChanged.connect(self.fun2)
        self.yolorect.stateChanged.connect(self.fun3)
        self.erzhihua.stateChanged.connect(self.fun4)
        self.danzhang.stateChanged.connect(self.fun5)

        self.danzhangjgcl.stateChanged.connect(self.fun_6)
        self.duozhangjgcl.stateChanged.connect(self.fun_7)
        self.dancamjgcl.stateChanged.connect(self.fun_8)
        self.duocamjgcl.stateChanged.connect(self.fun_9)
        self.zibiaozhu.stateChanged.connect(self.fun_9_1)

        self.okimgsave.stateChanged.connect(self.fun6)
        self.ngimgsave.stateChanged.connect(self.fun7)
        self.imgbmpsave.stateChanged.connect(self.fun8)
        self.flasksend.stateChanged.connect(self.fun8_1)
        self.tcpsend.stateChanged.connect(self.fun8_2)
        self.ngimgret.stateChanged.connect(self.fun_10)

        self.haikang.stateChanged.connect(self.fun9)
        self.daheng.stateChanged.connect(self.fun10)
        self.dushen.stateChanged.connect(self.fun11)
        self.maide.stateChanged.connect(self.fun12)
        self.dalsa.stateChanged.connect(self.fun13)
        self.usbcamera.stateChanged.connect(self.fun14)
        self.moni.stateChanged.connect(self.fun15)
        self.webcamera.stateChanged.connect(self.fun15_2)
        self.webcameraonepice.stateChanged.connect(self.fun15_3)

        self.setcamnum = 1
        self.setsuanfanum = 0
        self.cbcaming.currentIndexChanged[int].connect(self.fun16)
        self.suanfanuber.currentIndexChanged[int].connect(self.fun16_1)
        self.bt3.clicked.connect(self.fun17)
        self.bt4.clicked.connect(self.fun20)

        self.guigebt.clicked.connect(self.fun20_1)
        self.jiemianshezhi.clicked.connect(self.fun20_2)
        self.mmpathbt.clicked.connect(self.fun20_3)
        self.mmpathbt2.clicked.connect(self.fun20_4)

        self.donotmodel.stateChanged.connect(self.fun18)
        self.isskip.stateChanged.connect(self.fun19)

        #wangkoutcp
        self.wangkoutcp.stateChanged.connect(self.fun21)
        self.webcbt1.clicked.connect(self.fun21_1)
        self.webcbt2.clicked.connect(self.fun21_2)
        self.webcbt3.clicked.connect(self.fun21_3)
        self.webcbt4.clicked.connect(self.fun21_4)

        self.chuankou.stateChanged.connect(self.fun22)

        self.ctsf.stateChanged.connect(self.fun23)
        self.mygpu_.stateChanged.connect(self.fun24)
        self.mycpu_.stateChanged.connect(self.fun25)

        self.ioout.stateChanged.connect(self.fun26)
        self.jianjie.stateChanged.connect(self.fun26_1)
        self.jianjie2.stateChanged.connect(self.fun26_2)
        self.modbusset.stateChanged.connect(self.fun28)
        self.ziqidong.stateChanged.connect(self.fun26_3)
        self.showsn.stateChanged.connect(self.fun26_4)

        self.cbiolist.currentIndexChanged[int].connect(self.fun27)

        self.settcpnum = 1
        self.tcplist.currentIndexChanged[int].connect(self.fun29)
        self.tcpset.clicked.connect(self.fun30)

    def __createLoginPage(self):
        hlayout0_1 = QHBoxLayout()
        self.denglu = QtWidgets.QPushButton(u'登录')
        zhanghum = QtWidgets.QLabel(f'账户名:')
        self.mname = QLineEdit()
        mima = QtWidgets.QLabel(f'密码:')
        self.mima = QLineEdit()
        self.biaohaoshezhi = QtWidgets.QPushButton(u'编号设置')
        self.biaohao = QLineEdit()
        if 'biaohao' in config:
            self.biaohao.setText(config['biaohao'])
        hlayout0_1.addWidget(self.denglu)
        hlayout0_1.addWidget(zhanghum)
        hlayout0_1.addWidget(self.mname)
        hlayout0_1.addWidget(mima)
        hlayout0_1.addWidget(self.mima)
        if config['saiwangtest']:
            hlayout0_1.addWidget(self.biaohaoshezhi)
            hlayout0_1.addWidget(self.biaohao)
        page = QWidget()
        vLayout = QVBoxLayout()
        vLayout.addLayout(hlayout0_1)
        vLayout.addStretch()
        page.setLayout(vLayout)
        return page

    def __createPretreatmentePage(self):
        yuchuli = QtWidgets.QLabel(f'预处理:')
        yuchuli.setStyleSheet("font-weight: bold;font-size: 18px;")
        hlayout0 = QHBoxLayout()
        hlayout0.addWidget(yuchuli)
        # 水平布局按照从左到右的顺序进行添加按钮部件。
        hlayout = QHBoxLayout()
        self.qiepian = QCheckBox('切片')
        if config['qiepian']:
            self.qiepian.setChecked(True)
        else:
            self.qiepian.setChecked(False)
        self.yolorect = QCheckBox('深度学习抠图')
        if config['yolorect']:
            self.yolorect.setChecked(True)
        else:
            self.yolorect.setChecked(False)
        self.erzhihua = QCheckBox('二值化提取')
        if config['erzhihua']:
            self.erzhihua.setChecked(True)
        else:
            self.erzhihua.setChecked(False)
        self.danzhang = QCheckBox('单张检测')
        if config['danzhang']:
            self.danzhang.setChecked(True)
        else:
            self.danzhang.setChecked(False)
        self.zedie = QCheckBox('是否折叠')
        self.changlabel = QtWidgets.QLabel(f'长')
        self.kuanlabel = QtWidgets.QLabel(f'宽')
        self.chang = QLineEdit()
        self.kuan = QLineEdit()
        if 'changck' in config:
            self.chang.setText(config['changck'])
        if 'kuanck' in config:
            self.kuan.setText(config['kuanck'])
        self.mybtck = QtWidgets.QPushButton(u'设置')
        hlayout.addWidget(self.qiepian)
        hlayout.addWidget(self.yolorect)
        hlayout.addWidget(self.erzhihua)
        hlayout.addWidget(self.danzhang)
        hlayout.addWidget(self.changlabel)
        hlayout.addWidget(self.chang)
        hlayout.addWidget(self.kuanlabel)
        hlayout.addWidget(self.kuan)
        hlayout.addWidget(self.mybtck)
        hlayout.addWidget(self.zedie)

        modelchoice = QtWidgets.QLabel(f'模型选择与CPU GPU选择:')
        hlayout2 = QHBoxLayout()
        hlayout2.addWidget(modelchoice)
        # 水平布局按照从左到右的顺序进行添加按钮部件。
        hlayout3 = QHBoxLayout()
        mubiaojiance = QCheckBox('目标检测')
        yuyifenge = QCheckBox('语义分割')
        fenlei = QCheckBox('图片分类')
        ocr = QCheckBox('ocr检测分类')
        self.ctsf = QCheckBox('传统算法')
        if 'ctsf' in config:
            if config['ctsf']:
                self.ctsf.setChecked(True)
            else:
                self.ctsf.setChecked(False)
        self.mygpu_ = QCheckBox('GPU')
        if 'GPU' in config:
            if config['GPU']:
                self.mygpu_.setChecked(True)
            else:
                self.mygpu_.setChecked(False)
        self.mycpu_ = QCheckBox('CPU')
        if 'CPU' in config:
            if config['CPU']:
                self.mycpu_.setChecked(True)
            else:
                self.mycpu_.setChecked(False)
        hlayout3.addWidget(mubiaojiance)
        hlayout3.addWidget(yuyifenge)
        hlayout3.addWidget(fenlei)
        hlayout3.addWidget(ocr)
        hlayout3.addWidget(self.ctsf)
        hlayout3.addWidget(self.mygpu_)
        hlayout3.addWidget(self.mycpu_)
        page = QWidget()
        vLayout = QVBoxLayout()
        vLayout.addLayout(hlayout0)
        vLayout.addLayout(hlayout)
        vLayout.addLayout(hlayout2)
        vLayout.addLayout(hlayout3)
        vLayout.addStretch()
        page.setLayout(vLayout)
        return page

    def __createParamsSetPage(self):
        canshu = QtWidgets.QLabel(f'参数设置:')
        canshu.setStyleSheet("font-weight: bold;font-size: 18px;")
        hlayout4 = QHBoxLayout()
        hlayout4.addWidget(canshu)
        # 水平布局按照从左到右的顺序进行添加按钮部件。
        hlayout5 = QHBoxLayout()
        softname = QtWidgets.QLabel(f'软件名称')
        self.softnametext = QLineEdit()
        if 'softnametext' in config:
            self.softnametext.setText(config['softnametext'])
        modelpath = QtWidgets.QLabel(f'模型路径')
        self.modelpathtext = QLineEdit()
        classid = QtWidgets.QLabel(f'分类代码')
        classidtext = QLineEdit()
        self.mybt1 = QtWidgets.QPushButton(u'设置')
        hlayout5.addWidget(softname)
        hlayout5.addWidget(self.softnametext)
        hlayout5.addWidget(modelpath)
        hlayout5.addWidget(self.modelpathtext)
        hlayout5.addWidget(classid)
        hlayout5.addWidget(classidtext)
        hlayout5.addWidget(self.mybt1)

        shuchushezhi = QtWidgets.QLabel(f'输出设置:')
        shuchushezhi.setStyleSheet("font-weight: bold;font-size: 18px;")
        hlayout6 = QHBoxLayout()
        hlayout6.addWidget(shuchushezhi)
        # 水平布局按照从左到右的顺序进行添加按钮部件。
        hlayout7 = QHBoxLayout()
        self.chuankou = QCheckBox('串口通讯')
        if 'chuankou' in config:
            if config['chuankou']:
                self.chuankou.setChecked(True)
            else:
                self.chuankou.setChecked(False)
        comkou = QtWidgets.QLabel(f'com')
        self.comkoutext = QLineEdit()
        self.comkoutext.setText('1')
        botelv = QtWidgets.QLabel(f'波特率')
        self.botelvtext = QLineEdit()
        self.botelvtext.setText('115200')
        hlayout7.addWidget(self.chuankou)
        hlayout7.addWidget(comkou)
        hlayout7.addWidget(self.comkoutext)
        hlayout7.addWidget(botelv)
        hlayout7.addWidget(self.botelvtext)

        hlayout8 = QHBoxLayout()
        self.wangkoutcp = QCheckBox('modbus 网口通讯TCP ')
        if 'wangkoutcp' in config:
            if config['wangkoutcp']:
                self.wangkoutcp.setChecked(True)
            else:
                self.wangkoutcp.setChecked(False)
        '''self.wangkouvlc = QCheckBox('VLC解码')
        self.wangkouopencv = QCheckBox('opencv解码')'''

        tcpnum = QtWidgets.QLabel(f'TCP个数')
        self.tcpnumtext = QLineEdit()
        if 'tcpnumtext' in config:
            self.tcpnumtext.setText(config['tcpnumtext'])
        self.tcplist = QComboBox()
        tcpli = 'TCP1 TCP2 TCP3 TCP4 TCP5 TCP6 TCP7 TCP8 '.split()
        self.tcplist.addItems(tcpli)
        ipadress = QtWidgets.QLabel(f'IP地址')
        self.ipadresstext = QLineEdit()
        if 'ipadresstext' in config:
            self.ipadresstext.setText(config['ipadresstext'])
        duankou = QtWidgets.QLabel(f'端口')
        self.duankoutext = QLineEdit()
        self.duankoutext.setText('502')
        if 'duankoutext' in config:
            self.duankoutext.setText(config['duankoutext'])
        self.tcpset = QtWidgets.QPushButton(u'TCP设置')

        hlayout8.addWidget(self.wangkoutcp)
        hlayout8.addWidget(tcpnum)
        hlayout8.addWidget(self.tcpnumtext)
        hlayout8.addWidget(self.tcplist)
        hlayout8.addWidget(ipadress)
        hlayout8.addWidget(self.ipadresstext)
        hlayout8.addWidget(duankou)
        hlayout8.addWidget(self.duankoutext)
        hlayout8.addWidget(self.tcpset)

        hlayout8_1 = QHBoxLayout()
        self.webcbt1 = QtWidgets.QPushButton('网络相机1设定')
        ipadress1 = QtWidgets.QLabel(f'IP地址')
        self.ipadresstext1 = QLineEdit()
        if 'ipadresstext1' in config:
            self.ipadresstext1.setText(config['ipadresstext1'])
        duankou1 = QtWidgets.QLabel(f'端口')
        self.duankoutext1 = QLineEdit()
        self.duankoutext1.setText('502')
        if 'duankoutext1' in config:
            self.duankoutext1.setText(config['duankoutext1'])
        yanshi1 = QtWidgets.QLabel(f'延时')
        self.yanshi1text1 = QLineEdit()
        if 'yanshi1text1' in config:
            self.yanshi1text1.setText(str(config['yanshi1text1']))

        hlayout8_1.addWidget(self.webcbt1)
        hlayout8_1.addWidget(ipadress1)
        hlayout8_1.addWidget(self.ipadresstext1)
        hlayout8_1.addWidget(duankou1)
        hlayout8_1.addWidget(self.duankoutext1)
        hlayout8_1.addWidget(yanshi1)
        hlayout8_1.addWidget(self.yanshi1text1)

        hlayout8_2 = QHBoxLayout()
        self.webcbt2 = QtWidgets.QPushButton('网络相机2设定')
        ipadress2 = QtWidgets.QLabel(f'IP地址')
        self.ipadresstext2 = QLineEdit()
        if 'ipadresstext2' in config:
            self.ipadresstext2.setText(config['ipadresstext2'])
        duankou2 = QtWidgets.QLabel(f'端口')
        self.duankoutext2 = QLineEdit()
        self.duankoutext2.setText('502')
        if 'duankoutext2' in config:
            self.duankoutext2.setText(config['duankoutext2'])
        yanshi2 = QtWidgets.QLabel(f'延时')
        self.yanshi2text2 = QLineEdit()
        if 'yanshi2text2' in config:
            self.yanshi2text2.setText(str(config['yanshi2text2']))

        hlayout8_2.addWidget(self.webcbt2)
        hlayout8_2.addWidget(ipadress2)
        hlayout8_2.addWidget(self.ipadresstext2)
        hlayout8_2.addWidget(duankou2)
        hlayout8_2.addWidget(self.duankoutext2)
        hlayout8_2.addWidget(yanshi2)
        hlayout8_2.addWidget(self.yanshi2text2)

        hlayout8_3 = QHBoxLayout()
        self.webcbt3 = QtWidgets.QPushButton('网络相机3设定')
        ipadress3 = QtWidgets.QLabel(f'IP地址')
        self.ipadresstext3 = QLineEdit()
        if 'ipadresstext3' in config:
            self.ipadresstext3.setText(config['ipadresstext3'])
        duankou3 = QtWidgets.QLabel(f'端口')
        self.duankoutext3 = QLineEdit()
        self.duankoutext3.setText('502')
        if 'duankoutext3' in config:
            self.duankoutext3.setText(config['duankoutext3'])
        yanshi3 = QtWidgets.QLabel(f'延时')
        self.yanshi3text3 = QLineEdit()
        if 'yanshi3text3' in config:
            self.yanshi3text3.setText(str(config['yanshi3text3']))

        hlayout8_3.addWidget(self.webcbt3)
        hlayout8_3.addWidget(ipadress3)
        hlayout8_3.addWidget(self.ipadresstext3)
        hlayout8_3.addWidget(duankou3)
        hlayout8_3.addWidget(self.duankoutext3)
        hlayout8_3.addWidget(yanshi3)
        hlayout8_3.addWidget(self.yanshi3text3)

        hlayout8_4 = QHBoxLayout()
        self.webcbt4 = QtWidgets.QPushButton('网络相机4设定')
        ipadress4 = QtWidgets.QLabel(f'IP地址')
        self.ipadresstext4 = QLineEdit()
        if 'ipadresstext4' in config:
            self.ipadresstext4.setText(config['ipadresstext4'])
        duankou4 = QtWidgets.QLabel(f'端口')
        self.duankoutext4 = QLineEdit()
        self.duankoutext4.setText('502')
        if 'duankoutext4' in config:
            self.duankoutext4.setText(config['duankoutext4'])
        yanshi4 = QtWidgets.QLabel(f'延时')
        self.yanshi4text4 = QLineEdit()
        if 'yanshi4text4' in config:
            self.yanshi4text4.setText(str(config['yanshi4text4']))

        hlayout8_4.addWidget(self.webcbt4)
        hlayout8_4.addWidget(ipadress4)
        hlayout8_4.addWidget(self.ipadresstext4)
        hlayout8_4.addWidget(duankou4)
        hlayout8_4.addWidget(self.duankoutext4)
        hlayout8_4.addWidget(yanshi4)
        hlayout8_4.addWidget(self.yanshi4text4)

        xiangji = QtWidgets.QLabel(f'相机选择与设置:')
        xiangji.setStyleSheet("font-weight: bold;font-size: 18px;")
        camnum = QtWidgets.QLabel(f'相机个数:')
        self.camnumtext = QLineEdit()
        if 'cameranum' in config:
            self.camnumtext.setText(str(config['cameranum']))
        self.bt1 = QtWidgets.QPushButton(u'设置')
        hlayout9 = QHBoxLayout()
        hlayout9.addWidget(xiangji)
        hlayout9.addWidget(camnum)
        hlayout9.addWidget(self.camnumtext)
        hlayout9.addWidget(self.bt1)
        hlayout10 = QHBoxLayout()
        self.haikang = QCheckBox('海康相机')
        if 'haikang' in config and config['haikang']:
            self.haikang.setChecked(True)
        else:
            self.haikang.setChecked(False)
        self.daheng = QCheckBox('大恒相机')
        if 'daheng' in config and config['daheng']:
            self.daheng.setChecked(True)
        else:
            self.daheng.setChecked(False)
        self.dushen = QCheckBox('度申相机')
        if 'dushen' in config and config['dushen']:
            self.dushen.setChecked(True)
        else:
            self.dushen.setChecked(False)
        self.maide = QCheckBox('迈德威视相机')
        if 'maide' in config and config['maide']:
            self.maide.setChecked(True)
        else:
            self.maide.setChecked(False)
        self.dalsa = QCheckBox('Dalsa')
        if 'dalsa' in config and config['dalsa']:
            self.dalsa.setChecked(True)
        else:
            self.dalsa.setChecked(False)
        self.usbcamera = QCheckBox('通用USB相机')
        if 'usbcamera' in config and config['usbcamera']:
            self.usbcamera.setChecked(True)
        else:
            self.usbcamera.setChecked(False)

        self.webcamera = QCheckBox('通用网络相机')
        if 'webcamera' in config and config['webcamera']:
            self.webcamera.setChecked(True)
        else:
            self.webcamera.setChecked(False)

        self.webcameraonepice = QCheckBox('通用网络相机拍照模式')
        if 'webcameraonepice' in config and config['webcameraonepice']:
            self.webcameraonepice.setChecked(True)
        else:
            self.webcameraonepice.setChecked(False)

        self.moni = QCheckBox('模拟相机')
        if 'moni' in config and config['moni']:
            self.moni.setChecked(True)
        else:
            self.moni.setChecked(False)
        self.ruanchufa = QCheckBox('软触发模式')
        hlayout10.addWidget(self.haikang)
        hlayout10.addWidget(self.daheng)
        hlayout10.addWidget(self.dushen)
        hlayout10.addWidget(self.maide)
        hlayout10.addWidget(self.dalsa)
        hlayout10.addWidget(self.usbcamera)
        hlayout10.addWidget(self.webcamera)
        hlayout10.addWidget(self.webcameraonepice)
        hlayout10.addWidget(self.moni)
        hlayout10.addWidget(self.ruanchufa)

        hlayout11 = QHBoxLayout()
        cam1name = QtWidgets.QLabel(f'相机1代码:')
        self.cam1nametext = QLineEdit()
        if 'cam1name' in config:
            self.cam1nametext.setText(config['cam1name'])
        # self.cam1nametext.setMaximumWidth(100)
        cam1test = QtWidgets.QLabel(f'相机1检测项:')
        self.cam1testtext = QLineEdit()
        if 'cam1text' in config:
            self.cam1testtext.setText(config['cam1text'])
        hlayout11.addWidget(cam1name)
        hlayout11.addWidget(self.cam1nametext)
        hlayout11.addWidget(cam1test)
        hlayout11.addWidget(self.cam1testtext)

        hlayout12 = QHBoxLayout()
        cam2name = QtWidgets.QLabel(f'相机2代码:')
        self.cam2nametext = QLineEdit()
        if 'cam2name' in config:
            self.cam2nametext.setText(config['cam2name'])
        # self.cam2nametext.setMaximumWidth(100)
        cam2test = QtWidgets.QLabel(f'相机2检测项:')
        self.cam2testtext = QLineEdit()
        if 'cam2text' in config:
            self.cam2testtext.setText(config['cam2text'])
        hlayout12.addWidget(cam2name)
        hlayout12.addWidget(self.cam2nametext)
        hlayout12.addWidget(cam2test)
        hlayout12.addWidget(self.cam2testtext)

        hlayout13 = QHBoxLayout()
        cam3name = QtWidgets.QLabel(f'相机3代码:')
        self.cam3nametext = QLineEdit()
        if 'cam3name' in config:
            self.cam3nametext.setText(config['cam3name'])
        # self.cam3nametext.setMaximumWidth(100)
        cam3test = QtWidgets.QLabel(f'相机3检测项:')
        self.cam3testtext = QLineEdit()
        if 'cam3text' in config:
            self.cam3testtext.setText(config['cam3text'])
        hlayout13.addWidget(cam3name)
        hlayout13.addWidget(self.cam3nametext)
        hlayout13.addWidget(cam3test)
        hlayout13.addWidget(self.cam3testtext)

        hlayout14 = QHBoxLayout()
        cam4name = QtWidgets.QLabel(f'相机4代码:')
        self.cam4nametext = QLineEdit()
        if 'cam4name' in config:
            self.cam4nametext.setText(config['cam4name'])
        # self.cam4nametext.setMaximumWidth(100)
        cam4test = QtWidgets.QLabel(f'相机4检测项:')
        self.cam4testtext = QLineEdit()
        if 'cam4text' in config:
            self.cam4testtext.setText(config['cam4text'])
        hlayout14.addWidget(cam4name)
        hlayout14.addWidget(self.cam4nametext)
        hlayout14.addWidget(cam4test)
        hlayout14.addWidget(self.cam4testtext)

        hlayout15 = QHBoxLayout()
        cam5name = QtWidgets.QLabel(f'相机5代码:')
        self.cam5nametext = QLineEdit()
        if 'cam5name' in config:
            self.cam5nametext.setText(config['cam5name'])
        # self.cam5nametext.setMaximumWidth(100)
        cam5test = QtWidgets.QLabel(f'相机5检测项:')
        self.cam5testtext = QLineEdit()
        if 'cam5text' in config:
            self.cam5testtext.setText(config['cam5text'])
        hlayout15.addWidget(cam5name)
        hlayout15.addWidget(self.cam5nametext)
        hlayout15.addWidget(cam5test)
        hlayout15.addWidget(self.cam5testtext)

        hlayout16 = QHBoxLayout()
        cam6name = QtWidgets.QLabel(f'相机6代码:')
        self.cam6nametext = QLineEdit()
        if 'cam6name' in config:
            self.cam6nametext.setText(config['cam6name'])
        # self.cam6nametext.setMaximumWidth(100)
        cam6test = QtWidgets.QLabel(f'相机6检测项:')
        self.cam6testtext = QLineEdit()
        if 'cam6text' in config:
            self.cam6testtext.setText(config['cam6text'])
        hlayout16.addWidget(cam6name)
        hlayout16.addWidget(self.cam6nametext)
        hlayout16.addWidget(cam6test)
        hlayout16.addWidget(self.cam6testtext)

        hlayout17 = QHBoxLayout()
        cam7name = QtWidgets.QLabel(f'相机7代码:')
        self.cam7nametext = QLineEdit()
        if 'cam7name' in config:
            self.cam7nametext.setText(config['cam7name'])
        # self.cam7nametext.setMaximumWidth(100)
        cam7test = QtWidgets.QLabel(f'相机7检测项:')
        self.cam7testtext = QLineEdit()
        if 'cam7text' in config:
            self.cam7testtext.setText(config['cam7text'])
        hlayout17.addWidget(cam7name)
        hlayout17.addWidget(self.cam7nametext)
        hlayout17.addWidget(cam7test)
        hlayout17.addWidget(self.cam7testtext)

        hlayout18 = QHBoxLayout()
        cam8name = QtWidgets.QLabel(f'相机8代码:')
        self.cam8nametext = QLineEdit()
        if 'cam8name' in config:
            self.cam8nametext.setText(config['cam8name'])
        # self.cam8nametext.setMaximumWidth(100)
        cam8test = QtWidgets.QLabel(f'相机8检测项:')
        self.cam8testtext = QLineEdit()
        if 'cam8text' in config:
            self.cam8testtext.setText(config['cam8text'])
        hlayout18.addWidget(cam8name)
        hlayout18.addWidget(self.cam8nametext)
        hlayout18.addWidget(cam8test)
        hlayout18.addWidget(self.cam8testtext)

        page = QWidget()
        vLayout = QVBoxLayout()
        vLayout.addLayout(hlayout4)
        vLayout.addLayout(hlayout5)
        vLayout.addLayout(hlayout11)
        vLayout.addLayout(hlayout12)
        vLayout.addLayout(hlayout13)
        vLayout.addLayout(hlayout14)
        vLayout.addLayout(hlayout15)
        vLayout.addLayout(hlayout16)
        vLayout.addLayout(hlayout17)
        vLayout.addLayout(hlayout18)
        vLayout.addStretch()
        page.setLayout(vLayout)
        return page

    def __createPosttreatmentPage(self):
        houchuli = QtWidgets.QLabel(f'后处理:')
        houchuli.setStyleSheet("font-weight: bold;font-size: 18px;")
        hlayout19 = QHBoxLayout()
        hlayout19.addWidget(houchuli)
        hlayout20 = QHBoxLayout()
        xiacileibie = QtWidgets.QLabel(f'瑕疵类别:')
        self.xiacileibietext = QLineEdit()
        self.xiacileibietext.setMaximumWidth(150)
        HWzhuanghua = QCheckBox('长宽转化')
        Areazhuanghua = QCheckBox('面积转化')
        self.danzhangjgcl = QCheckBox('单张结果处理')
        if 'danzhangjgcl' in config and config['danzhangjgcl']:
            self.danzhangjgcl.setChecked(True)
        else:
            self.danzhangjgcl.setChecked(False)
        self.duozhangjgcl = QCheckBox('多张张结果处理')
        if 'duozhangjgcl' in config and config['duozhangjgcl']:
            self.duozhangjgcl.setChecked(True)
        else:
            self.duozhangjgcl.setChecked(False)
        self.dancamjgcl = QCheckBox('单相机结果处理')
        if 'dancamjgcl' in config and config['dancamjgcl']:
            self.dancamjgcl.setChecked(True)
        else:
            self.dancamjgcl.setChecked(False)
        self.duocamjgcl = QCheckBox('多相机结果处理')
        if 'duocamjgcl' in config and config['duocamjgcl']:
            self.duocamjgcl.setChecked(True)
        else:
            self.duocamjgcl.setChecked(False)

        self.zibiaozhu = QCheckBox('自动标注')
        if 'zibiaozhu' in config and config['zibiaozhu']:
            self.zibiaozhu.setChecked(True)
        else:
            self.zibiaozhu.setChecked(False)

        bt2 = QtWidgets.QPushButton(u'设置')
        hlayout20.addWidget(xiacileibie)
        hlayout20.addWidget(self.xiacileibietext)
        hlayout20.addWidget(HWzhuanghua)
        hlayout20.addWidget(Areazhuanghua)
        hlayout20.addWidget(self.danzhangjgcl)
        hlayout20.addWidget(self.duozhangjgcl)
        hlayout20.addWidget(self.dancamjgcl)
        hlayout20.addWidget(self.duocamjgcl)
        hlayout20.addWidget(self.zibiaozhu)
        hlayout20.addWidget(bt2)
        page = QWidget()
        vLayout = QVBoxLayout()
        vLayout.addLayout(hlayout19)
        vLayout.addLayout(hlayout20)
        vLayout.addStretch()
        page.setLayout(vLayout)
        return page

    def __createImageSavePage(self):
        imgsave = QtWidgets.QLabel(f'图像保存:')
        imgsave.setStyleSheet("font-weight: bold;font-size: 18px;")
        hlayout21 = QHBoxLayout()
        hlayout21.addWidget(imgsave)
        hlayout22 = QHBoxLayout()
        self.okimgsave = QCheckBox('保存良品图片')
        if 'okimgsave' in config and config['okimgsave']:
            self.okimgsave.setChecked(True)
        else:
            self.okimgsave.setChecked(False)
        self.ngimgsave = QCheckBox('保存不良图片')
        if 'ngimgsave' in config and config['ngimgsave']:
            self.ngimgsave.setChecked(True)
        else:
            self.ngimgsave.setChecked(False)

        self.ngimgret = QCheckBox('保存不良品效果图')
        if 'ngimgret' in config and config['ngimgret']:
            self.ngimgret.setChecked(True)
        else:
            self.ngimgret.setChecked(False)

        self.imgbmpsave = QCheckBox('是否保存bmp格式')
        if 'imgbmpsave' in config and config['imgbmpsave']:
            self.imgbmpsave.setChecked(True)
        else:
            self.imgbmpsave.setChecked(False)

        self.flasksend = QCheckBox('上传服务器')
        if 'flasksend' in config and config['flasksend']:
            self.flasksend.setChecked(True)
        else:
            self.flasksend.setChecked(False)
        self.tcpsend = QCheckBox('上传TCP')
        if 'tcpsend' in config and config['tcpsend']:
            self.tcpsend.setChecked(True)
        else:
            self.tcpsend.setChecked(False)
        tcpsendipadress = QtWidgets.QLabel(f'IP地址')
        self.tcpsendipadresstext = QLineEdit()
        if 'tcpsendipadresstext' in config:
            self.tcpsendipadresstext.setText(config['tcpsendipadresstext'])
        tcpsendduankou = QtWidgets.QLabel(f'端口')
        self.tcpsendduankoutext = QLineEdit()
        if 'tcpsendduankoutext' in config:
            self.tcpsendduankoutext.setText(str(config['tcpsendduankoutext']))
        hlayout22.addWidget(self.okimgsave)
        hlayout22.addWidget(self.ngimgsave)
        hlayout22.addWidget(self.imgbmpsave)
        hlayout22.addWidget(self.ngimgret)
        hlayout22.addWidget(self.flasksend)
        hlayout22.addWidget(self.tcpsend)
        hlayout22.addWidget(tcpsendipadress)
        hlayout22.addWidget(self.tcpsendipadresstext)
        hlayout22.addWidget(tcpsendduankou)
        hlayout22.addWidget(self.tcpsendduankoutext)
        page = QWidget()
        vLayout = QVBoxLayout()
        vLayout.addLayout(hlayout21)
        vLayout.addLayout(hlayout22)
        vLayout.addStretch()
        page.setLayout(vLayout)
        return page

    def __createCameraSizeAndAlg(self):
        camimgset = QtWidgets.QLabel(f'相机图像尺寸及算法设定:')
        camimgset.setStyleSheet("font-weight: bold;font-size: 18px;")
        hlayout23 = QHBoxLayout()
        hlayout23.addWidget(camimgset)
        hlayout24 = QHBoxLayout()
        self.cbcaming = QComboBox(self)
        li = 'Camera1 Camera2 Camera3 Camera4 Camera5 Camera6 Camera7 Camera8 '.split()
        self.cbcaming.addItems(li)

        self.suanfanuber = QComboBox(self)
        lisuanfa = '算法1 算法2 算法3 算法4'.split()
        self.suanfanuber.addItems(lisuanfa)

        self.myw = QLineEdit()
        self.myH = QLineEdit()
        self.bt3 = QtWidgets.QPushButton(u'设置')
        hlayout24.addWidget(self.cbcaming)
        hlayout24.addWidget(self.suanfanuber)
        hlayout24.addWidget(self.myw)
        hlayout24.addWidget(self.myH)
        hlayout24.addWidget(self.bt3)
        page = QWidget()
        vLayout = QVBoxLayout()
        vLayout.addLayout(hlayout23)
        vLayout.addLayout(hlayout24)
        vLayout.addStretch()
        page.setLayout(vLayout)
        return page

    def __createDebugPage(self):
        tiaoshi = QtWidgets.QLabel(f'调试:')
        tiaoshi.setStyleSheet("font-weight: bold;font-size: 18px;")
        hlayout25 = QHBoxLayout()
        hlayout25.addWidget(tiaoshi)
        hlayout26 = QHBoxLayout()
        self.donotmodel = QCheckBox('不运行算法模型')
        if 'donotmodel' in config and config['donotmodel']:
            self.donotmodel.setChecked(True)
        else:
            self.donotmodel.setChecked(False)

        self.isskip = QCheckBox('是否跳帧')
        if 'isskip' in config and config['isskip']:
            self.isskip.setChecked(True)
        else:
            self.isskip.setChecked(False)
        self.bt4 = QtWidgets.QPushButton(u'Modbus')
        hlayout26.addWidget(self.donotmodel)
        hlayout26.addWidget(self.isskip)
        hlayout26.addWidget(self.bt4)

        hlayout27 = QHBoxLayout()
        self.modbusset = QCheckBox('modbus设置')
        congzhanid = QtWidgets.QLabel(f'从站ID:')
        self.congzhanidtext = QLineEdit()
        startaddr = QtWidgets.QLabel(f'写入起始地址:')
        self.startaddrtext = QLineEdit()
        readstartaddr = QtWidgets.QLabel(f'读取起始地址:')
        self.readstartaddrtext = QLineEdit()
        self.ioout = QCheckBox('IO输出')
        if 'IOctr' in config and config['IOctr']:
            self.ioout.setChecked(True)
        else:
            self.ioout.setChecked(False)
        self.iolist = 'PCI-1750 PCIE-1730 LeiShai'.split()
        self.cbiolist = QComboBox(self)
        self.cbiolist.addItems(self.iolist)
        hlayout27.addWidget(self.modbusset)
        hlayout27.addWidget(congzhanid)
        hlayout27.addWidget(self.congzhanidtext)
        hlayout27.addWidget(startaddr)
        hlayout27.addWidget(self.startaddrtext)
        hlayout27.addWidget(readstartaddr)
        hlayout27.addWidget(self.readstartaddrtext)
        hlayout27.addWidget(self.ioout)
        hlayout27.addWidget(self.cbiolist)

        hlayout28 = QHBoxLayout()
        guige = QtWidgets.QLabel(f'产品规格列表:')
        self.guigetext = QLineEdit()
        if 'guigetext' in config:
            self.guigetext.setText(config['guigetext'])
        self.guigebt = QtWidgets.QPushButton(u'设置')
        hlayout28.addWidget(guige)
        hlayout28.addWidget(self.guigetext)
        hlayout28.addWidget(self.guigebt)
        page = QWidget()
        vLayout = QVBoxLayout()
        vLayout.addLayout(hlayout25)
        vLayout.addLayout(hlayout26)
        vLayout.addLayout(hlayout27)
        vLayout.addLayout(hlayout28)
        vLayout.addStretch()
        page.setLayout(vLayout)
        return page

    def __createUiSetPage(self):
        hlayout29 = QHBoxLayout()
        jiemian = QtWidgets.QLabel(f'界面设置:')
        jiemian.setStyleSheet("font-weight: bold;font-size: 18px;")
        maxW = QtWidgets.QLabel(f'单相机界面宽:')
        self.maxWtext = QLineEdit()
        maxH = QtWidgets.QLabel(f'单相机界面高:')
        self.maxHtext = QLineEdit()
        self.jianjie = QCheckBox('隐藏设置框')
        if 'jianjie' in config and config['jianjie']:
            self.jianjie.setChecked(True)
        else:
            self.jianjie.setChecked(False)
        self.jianjie2 = QCheckBox('隐藏相机名称及参数')
        if 'jianjie2' in config and config['jianjie2']:
            self.jianjie2.setChecked(True)
        else:
            self.jianjie2.setChecked(False)
        self.jiemianshezhi = QtWidgets.QPushButton(u'设置')
        #hlayout29.addWidget(jiemian)
        hlayout29.addWidget(maxW)
        hlayout29.addWidget(self.maxWtext)
        hlayout29.addWidget(maxH)
        hlayout29.addWidget(self.maxHtext)
        hlayout29.addWidget(self.jianjie)
        hlayout29.addWidget(self.jianjie2)
        hlayout29.addWidget(self.jiemianshezhi)

        hlayout30 = QHBoxLayout()
        mmodelpathlabel = QtWidgets.QLabel(f'模型路径1:')
        self.mmodelpath = QLineEdit()
        self.mmodelpath.setMinimumWidth(450)
        if 'mmodelpath' in config:
            self.mmodelpath.setText(config['mmodelpath'])
        self.mmpathbt = QtWidgets.QPushButton(u'设置')
        hlayout30.addWidget(mmodelpathlabel)
        hlayout30.addWidget(self.mmodelpath)
        hlayout30.addWidget(self.mmpathbt)

        hlayout31 = QHBoxLayout()
        mmodelpathlabel2 = QtWidgets.QLabel(f'模型路径2:')
        self.mmodelpath2 = QLineEdit()
        if 'mmodelpath2' in config:
            self.mmodelpath2.setText(config['mmodelpath2'])
        self.mmpathbt2 = QtWidgets.QPushButton(u'设置')
        hlayout31.addWidget(mmodelpathlabel2)
        hlayout31.addWidget(self.mmodelpath2)
        hlayout31.addWidget(self.mmpathbt2)

        hlayout32 = QHBoxLayout()
        self.ziqidong = QCheckBox('软件自启动')
        if 'ziqidong' in config and config['ziqidong']:
            self.ziqidong.setChecked(True)
        else:
            self.ziqidong.setChecked(False)
        self.showsn = QCheckBox('SN显示')
        if 'showsn' in config and config['showsn']:
            self.showsn.setChecked(True)
        else:
            self.showsn.setChecked(False)
        hlayout32.addWidget(self.ziqidong)
        hlayout32.addWidget(self.showsn)

        # layouttanhaunag = QGridLayout()
        # # Add a vertical spring to the layout
        # spring = QSpacerItem(
        #     20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
        # layouttanhaunag.addItem(spring, 0, 0)
        page = QWidget()
        vLayout = QVBoxLayout()
        vLayout.addWidget(jiemian)
        vLayout.addLayout(hlayout29)
        vLayout.addLayout(hlayout30)
        vLayout.addLayout(hlayout31)
        vLayout.addLayout(hlayout32)
        vLayout.addStretch()
        page.setLayout(vLayout)
        return page

    def fun_11(self):
        mname = self.mname.text()
        mima = self.mima.text()
        if config['mname'] == mname and config['mima'] == mima:
            config['denglu'] = True
            self.denglu.setText('登录成功')
            print("登录成功")
        else:
            config['denglu'] = False
            print("登录失败")
            self.denglu.setText('登录失败')
        config_save()

    def fun_13(self):
        biaohao = self.biaohao.text()
        config['biaohao'] = biaohao
        config_save()
        print("编号设置")


    def fun_12(self):
        nametsr = self.softnametext.text()
        config['softnametext'] = nametsr
        config['modelpathtext'] = self.modelpathtext.text()
        config_save()
        print("参数设置")

    def fun_1(self):
        nametsr = self.softnametext.text()
        config['softnametext'] = nametsr
        config['modelpathtext'] = self.modelpathtext.text()
        config_save()
        print("参数设置")
    def fun_ck(self):
        config['changck'] = self.chang.text()
        config['kuanck'] = self.kuan.text()
        config_save()
        print("模型长宽参数设置")

    def fun1(self):
        num = int(self.camnumtext.text())
        config['cameranum'] = num

        ctr = self.cam1nametext.text()
        ctrtext =self.cam1testtext.text()
        config['cam1name'] = ctr
        config['cam1text'] = ctrtext

        ctr = self.cam2nametext.text()
        ctrtext = self.cam2testtext.text()
        config['cam2name'] = ctr
        config['cam2text'] = ctrtext

        ctr = self.cam3nametext.text()
        ctrtext = self.cam3testtext.text()
        config['cam3name'] = ctr
        config['cam3text'] = ctrtext

        ctr = self.cam4nametext.text()
        ctrtext = self.cam4testtext.text()
        config['cam4name'] = ctr
        config['cam4text'] = ctrtext

        ctr = self.cam5nametext.text()
        ctrtext = self.cam5testtext.text()
        config['cam5name'] = ctr
        config['cam5text'] = ctrtext

        ctr = self.cam6nametext.text()
        ctrtext = self.cam6testtext.text()
        config['cam6name'] = ctr
        config['cam6text'] = ctrtext

        ctr = self.cam7nametext.text()
        ctrtext = self.cam7testtext.text()
        config['cam7name'] = ctr
        config['cam7text'] = ctrtext

        ctr = self.cam8nametext.text()
        ctrtext = self.cam8testtext.text()
        config['cam8name'] = ctr
        config['cam8text'] = ctrtext

        config_save()
        print("相机设置")
        pass

    def fun2(self):
        config['qiepian'] = self.qiepian.checkState()
        config_save()
        print("切片")
    def fun3(self):
        print("深度学习截取")
        config['yolorect'] = self.yolorect.checkState()
        config_save()
    def fun4(self):
        print("二值化提取")
        config['erzhihua'] = self.erzhihua.checkState()
        config_save()
    def fun5(self):
        print("单张")
        config['danzhang'] = self.danzhang.checkState()
        config_save()
    def fun6(self):
        config['okimgsave'] = self.okimgsave.checkState()
        config_save()
        print("ok图片保存")

    def fun_6(self):
        config['danzhangjgcl'] = self.danzhangjgcl.checkState()
        config_save()
        print("单张图片结果处理")

    def fun_7(self):
        config['duozhangjgcl'] = self.duozhangjgcl.checkState()
        config_save()
        print("多张图片结果处理")

    def fun_8(self):
        config['dancamjgcl'] = self.dancamjgcl.checkState()
        config_save()
        print("单相机结果处理")

    def fun_9(self):
        config['duocamjgcl'] = self.duocamjgcl.checkState()
        config_save()
        print("多相机结果处理")


    def fun_9_1(self):
        config['zibiaozhu'] = self.zibiaozhu.checkState()
        config_save()
        print("自动标注")

    def fun7(self):
        config['ngimgsave'] = self.ngimgsave.checkState()
        config_save()
        print("Ng图片保存")
    def fun8(self):
        config['imgbmpsave'] = self.imgbmpsave.checkState()
        config_save()
        print("bmp图片保存")

    def fun8_1(self):
        config['flasksend'] = self.flasksend.checkState()
        config_save()
        print("图片上传服务器")

    def fun8_2(self):
        config['tcpsend'] = self.tcpsend.checkState()
        config['tcpsendipadresstext'] = self.tcpsendipadresstext.text()
        config['tcpsendduankoutext'] = int(self.tcpsendduankoutext.text())
        config_save()
        print("TCP上传")


    def fun_10(self):
        config['ngimgret'] = self.ngimgret.checkState()
        config_save()
        print("保存不良品效果图")
    #ngimgret
    def fun9(self):
        config['haikang'] = self.haikang.checkState()
        config_save()
        print("海康相机")
    def fun10(self):
        config['daheng'] = self.daheng.checkState()
        config_save()
        print("大恒相机")
    def fun11(self):
        config['dushen'] = self.dushen.checkState()
        config_save()
        print("度申")
    def fun12(self):
        config['maide'] = self.maide.checkState()
        config_save()
        print("迈德威视")
    def fun13(self):
        config['dalsa'] = self.dalsa.checkState()
        config_save()
        print("Dalsa")
    def fun14(self):
        config['usbcamera'] = self.usbcamera.checkState()
        config_save()
        print("USB相机")
    def fun15(self):
        config['moni'] = self.moni.checkState()
        config_save()
        print("模拟相机")

    def fun15_2(self):
        config['webcamera'] = self.webcamera.checkState()
        config_save()
        print("网络相机")

    def fun15_3(self):
        config['webcameraonepice'] = self.webcameraonepice.checkState()
        config_save()
        print("通用网络相机拍照模式")

    def fun16(self,i):
        self.setcamnum = i + 1
        print("img set Camera:",i+1)

    def fun16_1(self,i):
        self.setsuanfanum = i
        print("设置算法:",i+1)

    def fun17(self):
        pa = f'Camera{self.setcamnum}'
        pa2 = f'Camera{self.setcamnum}suanfa'
        w = int(self.myw.text())
        h = int(self.myH.text())
        config[pa] = [w,h]
        config[pa2] = self.setsuanfanum
        config_save()
        print(f'set Camera{self.setcamnum} {w} {h}')

    def fun18(self):
        config['donotmodel'] = self.donotmodel.checkState()
        config_save()
        print("不运行模型算法")
    def fun19(self):
        config['isskip'] = self.isskip.checkState()
        config_save()
        print("是否跳帧")

    def fun20(self):
        self.mb = ModbusAssistant.ModbusAssistant()
        self.mb.show()

    def fun20_1(self):
        config['guigetext'] = self.guigetext.text()
        config_save()
        print("规格列表")

    def fun20_2(self):
        config['maxWtext'] = self.maxWtext.text()
        config['maxHtext'] = self.maxHtext.text()
        config_save()
        print("界面单相机长宽设置")

    def fun20_3(self):
        config['mmodelpath'] = self.mmodelpath.text()
        config_save()
        print("模型1加载路径设置")

    def fun20_4(self):
        config['mmodelpath2'] = self.mmodelpath2.text()
        config_save()
        print("模型2加载路径设置")

    def fun21(self):
        config['wangkoutcp'] = self.wangkoutcp.checkState()
        config['ipadresstext'] = self.ipadresstext.text()
        config['duankoutext'] = self.duankoutext.text()
        config['tcpnumtext'] = self.tcpnumtext.text()
        config_save()
        print("网口通讯")

    def fun21_1(self):
        config['ipadresstext1'] = self.ipadresstext1.text()
        config['duankoutext1'] = self.duankoutext1.text()
        config['yanshi1text1'] = int(self.yanshi1text1.text())
        config_save()
        print("网络相机1")

    def fun21_2(self):
        config['ipadresstext2'] = self.ipadresstext2.text()
        config['duankoutext2'] = self.duankoutext2.text()
        config['yanshi2text2'] = int(self.yanshi2text2.text())
        config_save()
        print("网络相机2")

    def fun21_3(self):
        config['ipadresstext3'] = self.ipadresstext3.text()
        config['duankoutext3'] = self.duankoutext3.text()
        config['yanshi3text3'] = int(self.yanshi3text3.text())
        config_save()
        print("网络相机3")

    def fun21_4(self):
        config['ipadresstext4'] = self.ipadresstext4.text()
        config['duankoutext4'] = self.duankoutext4.text()
        config['yanshi4text4'] = int(self.yanshi4text4.text())
        config_save()
        print("网络相机4")

    def fun22(self):
        config['chuankou'] = self.chuankou.checkState()
        config_save()
        print("串口通讯")

    def fun23(self):
        config['ctsf'] = self.ctsf.checkState()
        config_save()
        print("使用传统算法")

    def fun24(self):
        config['GPU'] = self.mygpu_.checkState()
        config_save()
        print("使用GPU")

    def fun25(self):
        config['CPU'] = self.mycpu_.checkState()
        config_save()
        print("使用CPU")

    def fun26(self):
        config['IOctr'] = self.ioout.checkState()
        config_save()
        print("使用IO")

    def fun26_1(self):
        config['jianjie'] = self.jianjie.checkState()
        config_save()
        print("隐藏设置框")

    def fun26_2(self):
        config['jianjie2'] = self.jianjie2.checkState()
        config_save()
        print("隐藏相机名称及参数")

    def fun26_3(self):
        config['ziqidong'] = self.ziqidong.checkState()
        config_save()
        print("软件自启动")

    def fun26_4(self):
        config['showsn'] = self.showsn.checkState()
        config_save()
        print("SN显示")

    def fun27(self,i):
        config['IOxinghao'] = self.iolist[i]
        config_save()
        print("IO型号:",config['IOxinghao'])

    def fun28(self):
        config['usemodbus'] = self.modbusset.checkState()
        config_save()
        print("使用modbus")

    def fun29(self,i):
        self.settcpnum = i + 1
        print("img set TCP:",i+1)

    def fun30(self):
        pa = f'TCP{self.settcpnum}'
        paduankou = f'TCPduankou{self.settcpnum}'
        config[pa] = self.ipadresstext.text()
        config[paduankou] = self.duankoutext.text()
        config_save()
        print(f'set TCP{self.settcpnum} {pa} {paduankou}')


if __name__ == "__main__":
        app = QApplication(sys.argv)
        form = AlgSetDlg()
        form.show()
        sys.exit(app.exec_())
